{
  "cells": [
    {
      "cell_type": "markdown",
      "source": [
        "# Linear Regression Part 2"
      ],
      "metadata": {}
    },
    {
      "cell_type": "code",
      "source": [
        "import numpy as np\n",
        "import pandas as pd\n",
        "import matplotlib.pyplot as plt\n",
        "\n",
        "import math\n",
        "\n",
        "import warnings\n",
        "warnings.filterwarnings(\"ignore\")\n",
        "\n",
        "# yahoo finance is used to fetch data \n",
        "import yfinance as yf\n",
        "yf.pdr_override()"
      ],
      "outputs": [],
      "execution_count": 1,
      "metadata": {
        "collapsed": false,
        "outputHidden": false,
        "inputHidden": false,
        "execution": {
          "iopub.status.busy": "2022-07-05T15:04:19.222Z",
          "iopub.execute_input": "2022-07-05T15:04:19.228Z",
          "iopub.status.idle": "2022-07-05T15:04:19.644Z",
          "shell.execute_reply": "2022-07-05T15:04:19.638Z"
        }
      }
    },
    {
      "cell_type": "code",
      "source": [
        "# input\n",
        "symbol = 'AMD'\n",
        "start = '2018-01-01'\n",
        "end = '2022-07-01'\n",
        "\n",
        "# Read data \n",
        "dataset = yf.download(symbol,start,end)\n",
        "\n",
        "# View Columns\n",
        "dataset.head()"
      ],
      "outputs": [
        {
          "output_type": "stream",
          "name": "stdout",
          "text": [
            "[*********************100%***********************]  1 of 1 completed\n"
          ]
        },
        {
          "output_type": "execute_result",
          "execution_count": 2,
          "data": {
            "text/plain": "             Open   High    Low  Close  Adj Close     Volume\nDate                                                        \n2018-01-02  10.42  11.02  10.34  10.98      10.98   44146300\n2018-01-03  11.61  12.14  11.36  11.55      11.55  154066700\n2018-01-04  12.10  12.43  11.97  12.12      12.12  109503000\n2018-01-05  12.19  12.22  11.66  11.88      11.88   63808900\n2018-01-08  12.01  12.30  11.85  12.28      12.28   63346000",
            "text/html": "<div>\n<style scoped>\n    .dataframe tbody tr th:only-of-type {\n        vertical-align: middle;\n    }\n\n    .dataframe tbody tr th {\n        vertical-align: top;\n    }\n\n    .dataframe thead th {\n        text-align: right;\n    }\n</style>\n<table border=\"1\" class=\"dataframe\">\n  <thead>\n    <tr style=\"text-align: right;\">\n      <th></th>\n      <th>Open</th>\n      <th>High</th>\n      <th>Low</th>\n      <th>Close</th>\n      <th>Adj Close</th>\n      <th>Volume</th>\n    </tr>\n    <tr>\n      <th>Date</th>\n      <th></th>\n      <th></th>\n      <th></th>\n      <th></th>\n      <th></th>\n      <th></th>\n    </tr>\n  </thead>\n  <tbody>\n    <tr>\n      <th>2018-01-02</th>\n      <td>10.42</td>\n      <td>11.02</td>\n      <td>10.34</td>\n      <td>10.98</td>\n      <td>10.98</td>\n      <td>44146300</td>\n    </tr>\n    <tr>\n      <th>2018-01-03</th>\n      <td>11.61</td>\n      <td>12.14</td>\n      <td>11.36</td>\n      <td>11.55</td>\n      <td>11.55</td>\n      <td>154066700</td>\n    </tr>\n    <tr>\n      <th>2018-01-04</th>\n      <td>12.10</td>\n      <td>12.43</td>\n      <td>11.97</td>\n      <td>12.12</td>\n      <td>12.12</td>\n      <td>109503000</td>\n    </tr>\n    <tr>\n      <th>2018-01-05</th>\n      <td>12.19</td>\n      <td>12.22</td>\n      <td>11.66</td>\n      <td>11.88</td>\n      <td>11.88</td>\n      <td>63808900</td>\n    </tr>\n    <tr>\n      <th>2018-01-08</th>\n      <td>12.01</td>\n      <td>12.30</td>\n      <td>11.85</td>\n      <td>12.28</td>\n      <td>12.28</td>\n      <td>63346000</td>\n    </tr>\n  </tbody>\n</table>\n</div>"
          },
          "metadata": {}
        }
      ],
      "execution_count": 2,
      "metadata": {
        "collapsed": false,
        "outputHidden": false,
        "inputHidden": false,
        "execution": {
          "iopub.status.busy": "2022-07-05T15:04:19.650Z",
          "iopub.execute_input": "2022-07-05T15:04:19.654Z",
          "iopub.status.idle": "2022-07-05T15:04:20.299Z",
          "shell.execute_reply": "2022-07-05T15:04:20.293Z"
        }
      }
    },
    {
      "cell_type": "code",
      "source": [
        "dataset['Open_Close'] = (dataset['Open'] - dataset['Adj Close'])/dataset['Open']\n",
        "dataset['High_Low'] = (dataset['High'] - dataset['Low'])/dataset['Low']\n",
        "dataset['Increase_Decrease'] = np.where(dataset['Volume'].shift(-1) > dataset['Volume'],1,0)\n",
        "dataset['Buy_Sell_on_Open'] = np.where(dataset['Open'].shift(-1) > dataset['Open'],1,0)\n",
        "dataset['Buy_Sell'] = np.where(dataset['Adj Close'].shift(-1) > dataset['Adj Close'],1,0)\n",
        "dataset['Returns'] = dataset['Adj Close'].pct_change()\n",
        "dataset = dataset.dropna()\n",
        "dataset.head()"
      ],
      "outputs": [
        {
          "output_type": "execute_result",
          "execution_count": 3,
          "data": {
            "text/plain": "             Open   High    Low  Close  Adj Close     Volume  Open_Close  \\\nDate                                                                       \n2018-01-03  11.61  12.14  11.36  11.55      11.55  154066700    0.005168   \n2018-01-04  12.10  12.43  11.97  12.12      12.12  109503000   -0.001653   \n2018-01-05  12.19  12.22  11.66  11.88      11.88   63808900    0.025431   \n2018-01-08  12.01  12.30  11.85  12.28      12.28   63346000   -0.022481   \n2018-01-09  12.00  12.02  11.71  11.82      11.82   62560900    0.015000   \n\n            High_Low  Increase_Decrease  Buy_Sell_on_Open  Buy_Sell   Returns  \nDate                                                                           \n2018-01-03  0.068662                  0                 1         1  0.051913  \n2018-01-04  0.038429                  0                 1         0  0.049351  \n2018-01-05  0.048027                  0                 0         1 -0.019802  \n2018-01-08  0.037975                  0                 0         0  0.033670  \n2018-01-09  0.026473                  0                 0         1 -0.037459  ",
            "text/html": "<div>\n<style scoped>\n    .dataframe tbody tr th:only-of-type {\n        vertical-align: middle;\n    }\n\n    .dataframe tbody tr th {\n        vertical-align: top;\n    }\n\n    .dataframe thead th {\n        text-align: right;\n    }\n</style>\n<table border=\"1\" class=\"dataframe\">\n  <thead>\n    <tr style=\"text-align: right;\">\n      <th></th>\n      <th>Open</th>\n      <th>High</th>\n      <th>Low</th>\n      <th>Close</th>\n      <th>Adj Close</th>\n      <th>Volume</th>\n      <th>Open_Close</th>\n      <th>High_Low</th>\n      <th>Increase_Decrease</th>\n      <th>Buy_Sell_on_Open</th>\n      <th>Buy_Sell</th>\n      <th>Returns</th>\n    </tr>\n    <tr>\n      <th>Date</th>\n      <th></th>\n      <th></th>\n      <th></th>\n      <th></th>\n      <th></th>\n      <th></th>\n      <th></th>\n      <th></th>\n      <th></th>\n      <th></th>\n      <th></th>\n      <th></th>\n    </tr>\n  </thead>\n  <tbody>\n    <tr>\n      <th>2018-01-03</th>\n      <td>11.61</td>\n      <td>12.14</td>\n      <td>11.36</td>\n      <td>11.55</td>\n      <td>11.55</td>\n      <td>154066700</td>\n      <td>0.005168</td>\n      <td>0.068662</td>\n      <td>0</td>\n      <td>1</td>\n      <td>1</td>\n      <td>0.051913</td>\n    </tr>\n    <tr>\n      <th>2018-01-04</th>\n      <td>12.10</td>\n      <td>12.43</td>\n      <td>11.97</td>\n      <td>12.12</td>\n      <td>12.12</td>\n      <td>109503000</td>\n      <td>-0.001653</td>\n      <td>0.038429</td>\n      <td>0</td>\n      <td>1</td>\n      <td>0</td>\n      <td>0.049351</td>\n    </tr>\n    <tr>\n      <th>2018-01-05</th>\n      <td>12.19</td>\n      <td>12.22</td>\n      <td>11.66</td>\n      <td>11.88</td>\n      <td>11.88</td>\n      <td>63808900</td>\n      <td>0.025431</td>\n      <td>0.048027</td>\n      <td>0</td>\n      <td>0</td>\n      <td>1</td>\n      <td>-0.019802</td>\n    </tr>\n    <tr>\n      <th>2018-01-08</th>\n      <td>12.01</td>\n      <td>12.30</td>\n      <td>11.85</td>\n      <td>12.28</td>\n      <td>12.28</td>\n      <td>63346000</td>\n      <td>-0.022481</td>\n      <td>0.037975</td>\n      <td>0</td>\n      <td>0</td>\n      <td>0</td>\n      <td>0.033670</td>\n    </tr>\n    <tr>\n      <th>2018-01-09</th>\n      <td>12.00</td>\n      <td>12.02</td>\n      <td>11.71</td>\n      <td>11.82</td>\n      <td>11.82</td>\n      <td>62560900</td>\n      <td>0.015000</td>\n      <td>0.026473</td>\n      <td>0</td>\n      <td>0</td>\n      <td>1</td>\n      <td>-0.037459</td>\n    </tr>\n  </tbody>\n</table>\n</div>"
          },
          "metadata": {}
        }
      ],
      "execution_count": 3,
      "metadata": {
        "collapsed": false,
        "outputHidden": false,
        "inputHidden": false,
        "execution": {
          "iopub.status.busy": "2022-07-05T15:04:20.305Z",
          "iopub.execute_input": "2022-07-05T15:04:20.310Z",
          "shell.execute_reply": "2022-07-05T15:04:20.332Z",
          "iopub.status.idle": "2022-07-05T15:04:20.342Z"
        }
      }
    },
    {
      "cell_type": "code",
      "source": [
        "dataset.tail()"
      ],
      "outputs": [
        {
          "output_type": "execute_result",
          "execution_count": 4,
          "data": {
            "text/plain": "                 Open       High        Low      Close  Adj Close     Volume  \\\nDate                                                                           \n2022-06-24  83.559998  87.529999  83.080002  87.080002  87.080002   88553900   \n2022-06-27  87.360001  88.220001  85.250000  86.160004  86.160004   74663500   \n2022-06-28  85.709999  86.730003  80.430000  80.779999  80.779999   95618600   \n2022-06-29  79.550003  79.750000  76.510002  77.989998  77.989998  104140900   \n2022-06-30  77.730003  78.910004  75.480003  76.470001  76.470001  105368600   \n\n            Open_Close  High_Low  Increase_Decrease  Buy_Sell_on_Open  \\\nDate                                                                    \n2022-06-24   -0.042125  0.053563                  0                 1   \n2022-06-27    0.013736  0.034839                  1                 0   \n2022-06-28    0.057520  0.078329                  1                 0   \n2022-06-29    0.019610  0.042347                  1                 0   \n2022-06-30    0.016210  0.045443                  0                 0   \n\n            Buy_Sell   Returns  \nDate                            \n2022-06-24         0  0.056412  \n2022-06-27         0 -0.010565  \n2022-06-28         0 -0.062442  \n2022-06-29         0 -0.034538  \n2022-06-30         0 -0.019490  ",
            "text/html": "<div>\n<style scoped>\n    .dataframe tbody tr th:only-of-type {\n        vertical-align: middle;\n    }\n\n    .dataframe tbody tr th {\n        vertical-align: top;\n    }\n\n    .dataframe thead th {\n        text-align: right;\n    }\n</style>\n<table border=\"1\" class=\"dataframe\">\n  <thead>\n    <tr style=\"text-align: right;\">\n      <th></th>\n      <th>Open</th>\n      <th>High</th>\n      <th>Low</th>\n      <th>Close</th>\n      <th>Adj Close</th>\n      <th>Volume</th>\n      <th>Open_Close</th>\n      <th>High_Low</th>\n      <th>Increase_Decrease</th>\n      <th>Buy_Sell_on_Open</th>\n      <th>Buy_Sell</th>\n      <th>Returns</th>\n    </tr>\n    <tr>\n      <th>Date</th>\n      <th></th>\n      <th></th>\n      <th></th>\n      <th></th>\n      <th></th>\n      <th></th>\n      <th></th>\n      <th></th>\n      <th></th>\n      <th></th>\n      <th></th>\n      <th></th>\n    </tr>\n  </thead>\n  <tbody>\n    <tr>\n      <th>2022-06-24</th>\n      <td>83.559998</td>\n      <td>87.529999</td>\n      <td>83.080002</td>\n      <td>87.080002</td>\n      <td>87.080002</td>\n      <td>88553900</td>\n      <td>-0.042125</td>\n      <td>0.053563</td>\n      <td>0</td>\n      <td>1</td>\n      <td>0</td>\n      <td>0.056412</td>\n    </tr>\n    <tr>\n      <th>2022-06-27</th>\n      <td>87.360001</td>\n      <td>88.220001</td>\n      <td>85.250000</td>\n      <td>86.160004</td>\n      <td>86.160004</td>\n      <td>74663500</td>\n      <td>0.013736</td>\n      <td>0.034839</td>\n      <td>1</td>\n      <td>0</td>\n      <td>0</td>\n      <td>-0.010565</td>\n    </tr>\n    <tr>\n      <th>2022-06-28</th>\n      <td>85.709999</td>\n      <td>86.730003</td>\n      <td>80.430000</td>\n      <td>80.779999</td>\n      <td>80.779999</td>\n      <td>95618600</td>\n      <td>0.057520</td>\n      <td>0.078329</td>\n      <td>1</td>\n      <td>0</td>\n      <td>0</td>\n      <td>-0.062442</td>\n    </tr>\n    <tr>\n      <th>2022-06-29</th>\n      <td>79.550003</td>\n      <td>79.750000</td>\n      <td>76.510002</td>\n      <td>77.989998</td>\n      <td>77.989998</td>\n      <td>104140900</td>\n      <td>0.019610</td>\n      <td>0.042347</td>\n      <td>1</td>\n      <td>0</td>\n      <td>0</td>\n      <td>-0.034538</td>\n    </tr>\n    <tr>\n      <th>2022-06-30</th>\n      <td>77.730003</td>\n      <td>78.910004</td>\n      <td>75.480003</td>\n      <td>76.470001</td>\n      <td>76.470001</td>\n      <td>105368600</td>\n      <td>0.016210</td>\n      <td>0.045443</td>\n      <td>0</td>\n      <td>0</td>\n      <td>0</td>\n      <td>-0.019490</td>\n    </tr>\n  </tbody>\n</table>\n</div>"
          },
          "metadata": {}
        }
      ],
      "execution_count": 4,
      "metadata": {
        "collapsed": true,
        "jupyter": {
          "source_hidden": false,
          "outputs_hidden": false
        },
        "nteract": {
          "transient": {
            "deleting": false
          }
        },
        "execution": {
          "iopub.status.busy": "2022-07-05T15:04:20.349Z",
          "iopub.execute_input": "2022-07-05T15:04:20.354Z",
          "iopub.status.idle": "2022-07-05T15:04:20.363Z",
          "shell.execute_reply": "2022-07-05T15:04:20.335Z"
        }
      }
    },
    {
      "cell_type": "code",
      "source": [
        "dataset.shape"
      ],
      "outputs": [
        {
          "output_type": "execute_result",
          "execution_count": 5,
          "data": {
            "text/plain": "(1131, 12)"
          },
          "metadata": {}
        }
      ],
      "execution_count": 5,
      "metadata": {
        "collapsed": true,
        "jupyter": {
          "source_hidden": false,
          "outputs_hidden": false
        },
        "nteract": {
          "transient": {
            "deleting": false
          }
        },
        "execution": {
          "iopub.status.busy": "2022-07-05T15:04:20.369Z",
          "iopub.execute_input": "2022-07-05T15:04:20.375Z",
          "iopub.status.idle": "2022-07-05T15:04:20.385Z",
          "shell.execute_reply": "2022-07-05T15:04:20.467Z"
        }
      }
    },
    {
      "cell_type": "code",
      "source": [
        "dataset.info()"
      ],
      "outputs": [
        {
          "output_type": "stream",
          "name": "stdout",
          "text": [
            "<class 'pandas.core.frame.DataFrame'>\n",
            "DatetimeIndex: 1131 entries, 2018-01-03 to 2022-06-30\n",
            "Data columns (total 12 columns):\n",
            " #   Column             Non-Null Count  Dtype  \n",
            "---  ------             --------------  -----  \n",
            " 0   Open               1131 non-null   float64\n",
            " 1   High               1131 non-null   float64\n",
            " 2   Low                1131 non-null   float64\n",
            " 3   Close              1131 non-null   float64\n",
            " 4   Adj Close          1131 non-null   float64\n",
            " 5   Volume             1131 non-null   int64  \n",
            " 6   Open_Close         1131 non-null   float64\n",
            " 7   High_Low           1131 non-null   float64\n",
            " 8   Increase_Decrease  1131 non-null   int32  \n",
            " 9   Buy_Sell_on_Open   1131 non-null   int32  \n",
            " 10  Buy_Sell           1131 non-null   int32  \n",
            " 11  Returns            1131 non-null   float64\n",
            "dtypes: float64(8), int32(3), int64(1)\n",
            "memory usage: 101.6 KB\n"
          ]
        }
      ],
      "execution_count": 6,
      "metadata": {
        "collapsed": true,
        "jupyter": {
          "source_hidden": false,
          "outputs_hidden": false
        },
        "nteract": {
          "transient": {
            "deleting": false
          }
        },
        "execution": {
          "iopub.status.busy": "2022-07-05T15:04:20.392Z",
          "iopub.execute_input": "2022-07-05T15:04:20.397Z",
          "iopub.status.idle": "2022-07-05T15:04:20.407Z",
          "shell.execute_reply": "2022-07-05T15:04:20.471Z"
        }
      }
    },
    {
      "cell_type": "code",
      "source": [
        "dataset.describe()"
      ],
      "outputs": [
        {
          "output_type": "execute_result",
          "execution_count": 7,
          "data": {
            "text/plain": "              Open         High          Low        Close    Adj Close  \\\ncount  1131.000000  1131.000000  1131.000000  1131.000000  1131.000000   \nmean     59.415703    60.633121    58.098355    59.372785    59.372785   \nstd      38.269743    39.053046    37.360840    38.194456    38.194456   \nmin       9.080000     9.770000     9.040000     9.530000     9.530000   \n25%      26.570001    27.235000    25.895000    26.365001    26.365001   \n50%      51.340000    52.299999    49.900002    51.709999    51.709999   \n75%      88.305000    90.355000    86.584999    88.424999    88.424999   \nmax     163.279999   164.460007   156.100006   161.910004   161.910004   \n\n             Volume   Open_Close     High_Low  Increase_Decrease  \\\ncount  1.131000e+03  1131.000000  1131.000000        1131.000000   \nmean   7.023436e+07    -0.000252     0.044467           0.468612   \nstd    3.667395e+07     0.029720     0.023066           0.499235   \nmin    1.670590e+07    -0.115245     0.012392           0.000000   \n25%    4.385690e+07    -0.016676     0.027543           0.000000   \n50%    5.858360e+07     0.001012     0.038686           0.000000   \n75%    8.713595e+07     0.016407     0.054838           1.000000   \nmax    3.250584e+08     0.124676     0.148305           1.000000   \n\n       Buy_Sell_on_Open     Buy_Sell      Returns  \ncount       1131.000000  1131.000000  1131.000000  \nmean           0.523431     0.511052     0.002356  \nstd            0.499672     0.500099     0.035892  \nmin            0.000000     0.000000    -0.154454  \n25%            0.000000     0.000000    -0.016983  \n50%            1.000000     1.000000     0.000744  \n75%            1.000000     1.000000     0.021183  \nmax            1.000000     1.000000     0.199481  ",
            "text/html": "<div>\n<style scoped>\n    .dataframe tbody tr th:only-of-type {\n        vertical-align: middle;\n    }\n\n    .dataframe tbody tr th {\n        vertical-align: top;\n    }\n\n    .dataframe thead th {\n        text-align: right;\n    }\n</style>\n<table border=\"1\" class=\"dataframe\">\n  <thead>\n    <tr style=\"text-align: right;\">\n      <th></th>\n      <th>Open</th>\n      <th>High</th>\n      <th>Low</th>\n      <th>Close</th>\n      <th>Adj Close</th>\n      <th>Volume</th>\n      <th>Open_Close</th>\n      <th>High_Low</th>\n      <th>Increase_Decrease</th>\n      <th>Buy_Sell_on_Open</th>\n      <th>Buy_Sell</th>\n      <th>Returns</th>\n    </tr>\n  </thead>\n  <tbody>\n    <tr>\n      <th>count</th>\n      <td>1131.000000</td>\n      <td>1131.000000</td>\n      <td>1131.000000</td>\n      <td>1131.000000</td>\n      <td>1131.000000</td>\n      <td>1.131000e+03</td>\n      <td>1131.000000</td>\n      <td>1131.000000</td>\n      <td>1131.000000</td>\n      <td>1131.000000</td>\n      <td>1131.000000</td>\n      <td>1131.000000</td>\n    </tr>\n    <tr>\n      <th>mean</th>\n      <td>59.415703</td>\n      <td>60.633121</td>\n      <td>58.098355</td>\n      <td>59.372785</td>\n      <td>59.372785</td>\n      <td>7.023436e+07</td>\n      <td>-0.000252</td>\n      <td>0.044467</td>\n      <td>0.468612</td>\n      <td>0.523431</td>\n      <td>0.511052</td>\n      <td>0.002356</td>\n    </tr>\n    <tr>\n      <th>std</th>\n      <td>38.269743</td>\n      <td>39.053046</td>\n      <td>37.360840</td>\n      <td>38.194456</td>\n      <td>38.194456</td>\n      <td>3.667395e+07</td>\n      <td>0.029720</td>\n      <td>0.023066</td>\n      <td>0.499235</td>\n      <td>0.499672</td>\n      <td>0.500099</td>\n      <td>0.035892</td>\n    </tr>\n    <tr>\n      <th>min</th>\n      <td>9.080000</td>\n      <td>9.770000</td>\n      <td>9.040000</td>\n      <td>9.530000</td>\n      <td>9.530000</td>\n      <td>1.670590e+07</td>\n      <td>-0.115245</td>\n      <td>0.012392</td>\n      <td>0.000000</td>\n      <td>0.000000</td>\n      <td>0.000000</td>\n      <td>-0.154454</td>\n    </tr>\n    <tr>\n      <th>25%</th>\n      <td>26.570001</td>\n      <td>27.235000</td>\n      <td>25.895000</td>\n      <td>26.365001</td>\n      <td>26.365001</td>\n      <td>4.385690e+07</td>\n      <td>-0.016676</td>\n      <td>0.027543</td>\n      <td>0.000000</td>\n      <td>0.000000</td>\n      <td>0.000000</td>\n      <td>-0.016983</td>\n    </tr>\n    <tr>\n      <th>50%</th>\n      <td>51.340000</td>\n      <td>52.299999</td>\n      <td>49.900002</td>\n      <td>51.709999</td>\n      <td>51.709999</td>\n      <td>5.858360e+07</td>\n      <td>0.001012</td>\n      <td>0.038686</td>\n      <td>0.000000</td>\n      <td>1.000000</td>\n      <td>1.000000</td>\n      <td>0.000744</td>\n    </tr>\n    <tr>\n      <th>75%</th>\n      <td>88.305000</td>\n      <td>90.355000</td>\n      <td>86.584999</td>\n      <td>88.424999</td>\n      <td>88.424999</td>\n      <td>8.713595e+07</td>\n      <td>0.016407</td>\n      <td>0.054838</td>\n      <td>1.000000</td>\n      <td>1.000000</td>\n      <td>1.000000</td>\n      <td>0.021183</td>\n    </tr>\n    <tr>\n      <th>max</th>\n      <td>163.279999</td>\n      <td>164.460007</td>\n      <td>156.100006</td>\n      <td>161.910004</td>\n      <td>161.910004</td>\n      <td>3.250584e+08</td>\n      <td>0.124676</td>\n      <td>0.148305</td>\n      <td>1.000000</td>\n      <td>1.000000</td>\n      <td>1.000000</td>\n      <td>0.199481</td>\n    </tr>\n  </tbody>\n</table>\n</div>"
          },
          "metadata": {}
        }
      ],
      "execution_count": 7,
      "metadata": {
        "collapsed": true,
        "jupyter": {
          "source_hidden": false,
          "outputs_hidden": false
        },
        "nteract": {
          "transient": {
            "deleting": false
          }
        },
        "execution": {
          "iopub.status.busy": "2022-07-05T15:04:20.414Z",
          "iopub.execute_input": "2022-07-05T15:04:20.419Z",
          "iopub.status.idle": "2022-07-05T15:04:20.431Z",
          "shell.execute_reply": "2022-07-05T15:04:20.475Z"
        }
      }
    },
    {
      "cell_type": "code",
      "source": [
        "from sklearn import preprocessing\n",
        "from sklearn import metrics\n",
        "from sklearn.model_selection import train_test_split\n",
        "from sklearn.linear_model import LinearRegression"
      ],
      "outputs": [],
      "execution_count": 8,
      "metadata": {
        "collapsed": false,
        "outputHidden": false,
        "inputHidden": false,
        "execution": {
          "iopub.status.busy": "2022-07-05T15:04:20.439Z",
          "iopub.execute_input": "2022-07-05T15:04:20.444Z",
          "iopub.status.idle": "2022-07-05T15:04:21.275Z",
          "shell.execute_reply": "2022-07-05T15:04:21.267Z"
        }
      }
    },
    {
      "cell_type": "code",
      "source": [
        "X = dataset[['High', 'Low', 'Open', 'Volume', 'High_Low', 'Open_Close', 'Returns']].values\n",
        "y = dataset['Adj Close'].values\n",
        "print(X)"
      ],
      "outputs": [
        {
          "output_type": "stream",
          "name": "stdout",
          "text": [
            "[[ 1.21400003e+01  1.13599997e+01  1.16099997e+01 ...  6.86620344e-02\n",
            "   5.16791281e-03  5.19126295e-02]\n",
            " [ 1.24300003e+01  1.19700003e+01  1.21000004e+01 ...  3.84294092e-02\n",
            "  -1.65285153e-03  4.93506221e-02]\n",
            " [ 1.22200003e+01  1.16599998e+01  1.21899996e+01 ...  4.80274809e-02\n",
            "   2.54306380e-02 -1.98019615e-02]\n",
            " ...\n",
            " [ 8.67300034e+01  8.04300003e+01  8.57099991e+01 ...  7.83290194e-02\n",
            "   5.75195468e-02 -6.24420224e-02]\n",
            " [ 7.97500000e+01  7.65100021e+01  7.95500031e+01 ...  4.23473765e-02\n",
            "   1.96103724e-02 -3.45382639e-02]\n",
            " [ 7.89100037e+01  7.54800034e+01  7.77300034e+01 ...  4.54425033e-02\n",
            "   1.62099843e-02 -1.94896357e-02]]\n"
          ]
        }
      ],
      "execution_count": 9,
      "metadata": {
        "collapsed": false,
        "outputHidden": false,
        "inputHidden": false,
        "execution": {
          "iopub.status.busy": "2022-07-05T15:04:21.282Z",
          "iopub.execute_input": "2022-07-05T15:04:21.286Z",
          "iopub.status.idle": "2022-07-05T15:04:21.296Z",
          "shell.execute_reply": "2022-07-05T15:04:21.550Z"
        }
      }
    },
    {
      "cell_type": "code",
      "source": [
        "print(X.dtype.names)"
      ],
      "outputs": [
        {
          "output_type": "stream",
          "name": "stdout",
          "text": [
            "None\n"
          ]
        }
      ],
      "execution_count": 10,
      "metadata": {
        "collapsed": true,
        "jupyter": {
          "source_hidden": false,
          "outputs_hidden": false
        },
        "nteract": {
          "transient": {
            "deleting": false
          }
        },
        "execution": {
          "iopub.status.busy": "2022-07-05T15:04:21.302Z",
          "iopub.execute_input": "2022-07-05T15:04:21.306Z",
          "iopub.status.idle": "2022-07-05T15:04:21.316Z",
          "shell.execute_reply": "2022-07-05T15:04:21.555Z"
        }
      }
    },
    {
      "cell_type": "code",
      "source": [
        "X"
      ],
      "outputs": [
        {
          "output_type": "execute_result",
          "execution_count": 11,
          "data": {
            "text/plain": "array([[ 1.21400003e+01,  1.13599997e+01,  1.16099997e+01, ...,\n         6.86620344e-02,  5.16791281e-03,  5.19126295e-02],\n       [ 1.24300003e+01,  1.19700003e+01,  1.21000004e+01, ...,\n         3.84294092e-02, -1.65285153e-03,  4.93506221e-02],\n       [ 1.22200003e+01,  1.16599998e+01,  1.21899996e+01, ...,\n         4.80274809e-02,  2.54306380e-02, -1.98019615e-02],\n       ...,\n       [ 8.67300034e+01,  8.04300003e+01,  8.57099991e+01, ...,\n         7.83290194e-02,  5.75195468e-02, -6.24420224e-02],\n       [ 7.97500000e+01,  7.65100021e+01,  7.95500031e+01, ...,\n         4.23473765e-02,  1.96103724e-02, -3.45382639e-02],\n       [ 7.89100037e+01,  7.54800034e+01,  7.77300034e+01, ...,\n         4.54425033e-02,  1.62099843e-02, -1.94896357e-02]])"
          },
          "metadata": {}
        }
      ],
      "execution_count": 11,
      "metadata": {
        "collapsed": true,
        "jupyter": {
          "source_hidden": false,
          "outputs_hidden": false
        },
        "nteract": {
          "transient": {
            "deleting": false
          }
        },
        "execution": {
          "iopub.status.busy": "2022-07-05T15:04:21.322Z",
          "iopub.execute_input": "2022-07-05T15:04:21.326Z",
          "iopub.status.idle": "2022-07-05T15:04:21.337Z",
          "shell.execute_reply": "2022-07-05T15:04:21.558Z"
        }
      }
    },
    {
      "cell_type": "code",
      "source": [
        "print(y)"
      ],
      "outputs": [
        {
          "output_type": "stream",
          "name": "stdout",
          "text": [
            "[11.55000019 12.11999989 11.88000011 ... 80.77999878 77.98999786\n",
            " 76.47000122]\n"
          ]
        }
      ],
      "execution_count": 12,
      "metadata": {
        "collapsed": false,
        "outputHidden": false,
        "inputHidden": false,
        "execution": {
          "iopub.status.busy": "2022-07-05T15:04:21.343Z",
          "iopub.execute_input": "2022-07-05T15:04:21.348Z",
          "iopub.status.idle": "2022-07-05T15:04:21.356Z",
          "shell.execute_reply": "2022-07-05T15:04:21.561Z"
        }
      }
    },
    {
      "cell_type": "code",
      "source": [
        "\n",
        "# Split data into testing and training sets\n",
        "X_train, X_test, y_train, y_test = train_test_split(X,y, test_size=0.3, random_state=1)"
      ],
      "outputs": [],
      "execution_count": 13,
      "metadata": {
        "collapsed": false,
        "outputHidden": false,
        "inputHidden": false,
        "execution": {
          "iopub.status.busy": "2022-07-05T15:04:21.363Z",
          "iopub.execute_input": "2022-07-05T15:04:21.367Z",
          "iopub.status.idle": "2022-07-05T15:04:21.375Z",
          "shell.execute_reply": "2022-07-05T15:04:21.564Z"
        }
      }
    },
    {
      "cell_type": "code",
      "source": [
        "# Create Regression Model \n",
        "model = LinearRegression()\n",
        "\n",
        "# Train the model\n",
        "model.fit(X_train, y_train)\n",
        "\n",
        "#Printing Coefficient\n",
        "print(model.coef_)"
      ],
      "outputs": [
        {
          "output_type": "stream",
          "name": "stdout",
          "text": [
            "[ 5.84601906e-01  6.39590277e-01 -2.23415020e-01 -2.63620981e-09\n",
            "  2.84446069e+00 -1.58266015e+01  7.02997795e+00]\n"
          ]
        }
      ],
      "execution_count": 14,
      "metadata": {
        "collapsed": false,
        "outputHidden": false,
        "inputHidden": false,
        "execution": {
          "iopub.status.busy": "2022-07-05T15:04:21.383Z",
          "iopub.execute_input": "2022-07-05T15:04:21.387Z",
          "iopub.status.idle": "2022-07-05T15:04:21.400Z",
          "shell.execute_reply": "2022-07-05T15:04:21.566Z"
        }
      }
    },
    {
      "cell_type": "code",
      "source": [
        "coeff_df = pd.DataFrame(model.coef_,X.dtype.names,columns={'Coefficient'})\n",
        "coeff_df"
      ],
      "outputs": [
        {
          "output_type": "execute_result",
          "execution_count": 15,
          "data": {
            "text/plain": "    Coefficient\n0  5.846019e-01\n1  6.395903e-01\n2 -2.234150e-01\n3 -2.636210e-09\n4  2.844461e+00\n5 -1.582660e+01\n6  7.029978e+00",
            "text/html": "<div>\n<style scoped>\n    .dataframe tbody tr th:only-of-type {\n        vertical-align: middle;\n    }\n\n    .dataframe tbody tr th {\n        vertical-align: top;\n    }\n\n    .dataframe thead th {\n        text-align: right;\n    }\n</style>\n<table border=\"1\" class=\"dataframe\">\n  <thead>\n    <tr style=\"text-align: right;\">\n      <th></th>\n      <th>Coefficient</th>\n    </tr>\n  </thead>\n  <tbody>\n    <tr>\n      <th>0</th>\n      <td>5.846019e-01</td>\n    </tr>\n    <tr>\n      <th>1</th>\n      <td>6.395903e-01</td>\n    </tr>\n    <tr>\n      <th>2</th>\n      <td>-2.234150e-01</td>\n    </tr>\n    <tr>\n      <th>3</th>\n      <td>-2.636210e-09</td>\n    </tr>\n    <tr>\n      <th>4</th>\n      <td>2.844461e+00</td>\n    </tr>\n    <tr>\n      <th>5</th>\n      <td>-1.582660e+01</td>\n    </tr>\n    <tr>\n      <th>6</th>\n      <td>7.029978e+00</td>\n    </tr>\n  </tbody>\n</table>\n</div>"
          },
          "metadata": {}
        }
      ],
      "execution_count": 15,
      "metadata": {
        "collapsed": true,
        "jupyter": {
          "source_hidden": false,
          "outputs_hidden": false
        },
        "nteract": {
          "transient": {
            "deleting": false
          }
        },
        "execution": {
          "iopub.status.busy": "2022-07-05T15:04:21.408Z",
          "iopub.execute_input": "2022-07-05T15:04:21.412Z",
          "iopub.status.idle": "2022-07-05T15:04:21.422Z",
          "shell.execute_reply": "2022-07-05T15:04:21.569Z"
        }
      }
    },
    {
      "cell_type": "code",
      "source": [
        "coeff_df = pd.DataFrame(model.coef_,['High', 'Low', 'Open', 'Volume', 'High_Low', 'Open_Close', 'Returns'],columns={'Coefficient'})\n",
        "coeff_df"
      ],
      "outputs": [
        {
          "output_type": "execute_result",
          "execution_count": 16,
          "data": {
            "text/plain": "             Coefficient\nHigh        5.846019e-01\nLow         6.395903e-01\nOpen       -2.234150e-01\nVolume     -2.636210e-09\nHigh_Low    2.844461e+00\nOpen_Close -1.582660e+01\nReturns     7.029978e+00",
            "text/html": "<div>\n<style scoped>\n    .dataframe tbody tr th:only-of-type {\n        vertical-align: middle;\n    }\n\n    .dataframe tbody tr th {\n        vertical-align: top;\n    }\n\n    .dataframe thead th {\n        text-align: right;\n    }\n</style>\n<table border=\"1\" class=\"dataframe\">\n  <thead>\n    <tr style=\"text-align: right;\">\n      <th></th>\n      <th>Coefficient</th>\n    </tr>\n  </thead>\n  <tbody>\n    <tr>\n      <th>High</th>\n      <td>5.846019e-01</td>\n    </tr>\n    <tr>\n      <th>Low</th>\n      <td>6.395903e-01</td>\n    </tr>\n    <tr>\n      <th>Open</th>\n      <td>-2.234150e-01</td>\n    </tr>\n    <tr>\n      <th>Volume</th>\n      <td>-2.636210e-09</td>\n    </tr>\n    <tr>\n      <th>High_Low</th>\n      <td>2.844461e+00</td>\n    </tr>\n    <tr>\n      <th>Open_Close</th>\n      <td>-1.582660e+01</td>\n    </tr>\n    <tr>\n      <th>Returns</th>\n      <td>7.029978e+00</td>\n    </tr>\n  </tbody>\n</table>\n</div>"
          },
          "metadata": {}
        }
      ],
      "execution_count": 16,
      "metadata": {
        "collapsed": true,
        "jupyter": {
          "source_hidden": false,
          "outputs_hidden": false
        },
        "nteract": {
          "transient": {
            "deleting": false
          }
        },
        "execution": {
          "iopub.status.busy": "2022-07-05T15:04:21.429Z",
          "iopub.execute_input": "2022-07-05T15:04:21.433Z",
          "iopub.status.idle": "2022-07-05T15:04:21.444Z",
          "shell.execute_reply": "2022-07-05T15:04:21.572Z"
        }
      }
    },
    {
      "cell_type": "code",
      "source": [
        "# Use model to make predictions\n",
        "predicted = model.predict(X_test) \n",
        "print(predicted)"
      ],
      "outputs": [
        {
          "output_type": "stream",
          "name": "stdout",
          "text": [
            "[ 31.42105278  27.23090196 134.78984403  13.11574906  20.65405771\n",
            "  44.26358767  47.47237552  90.59455346  94.99462391  19.75571156\n",
            "  14.2136152  113.35255987  48.66319552  79.99592407  19.05501715\n",
            " 107.8987487   54.13078413  56.17487692  11.6369291   84.40197077\n",
            "  29.99936335  84.87449735  81.94094415  12.270629    19.07151905\n",
            "  48.76646329  29.51864084  42.84064194  14.41629136  17.19040892\n",
            "  16.67241618 105.25472876  33.19687491  91.08043651  25.82475013\n",
            "  52.56865007 148.44496459  76.31907977  54.74599391 121.17217296\n",
            "  78.62681065 106.05898113  25.12196183  57.08346591 107.23210252\n",
            "  15.95670337  11.68010161  35.33829754  23.55834813  11.43952202\n",
            "  74.60650295  44.33523442  39.49788808  52.95734184  83.23372208\n",
            "  91.43367678  34.34762101  15.88694723  19.80925245  57.47260497\n",
            "  16.89672363  23.98461345  53.65573184  31.05036593 104.38604163\n",
            "  80.9785897   75.37049523  96.2147226   89.17926451   9.30590811\n",
            "  95.44373476 137.73295576  77.17301171 105.50348692  93.8865632\n",
            "  29.97593995  94.6193796   27.63813633  20.52107926  31.49270174\n",
            "  73.29084565  26.94347122  76.64603979 112.43407253  12.53115314\n",
            "  12.28058176 108.89627944  32.71119272  25.65416835  74.87498475\n",
            "  39.08268826  90.59311109  95.02462284  79.06238906  10.59199888\n",
            "  82.66222774  83.60952252  31.53097581  31.19779171  17.04781667\n",
            "  91.26630405 109.44894569  21.56663023 150.91461606  25.95942388\n",
            "  87.82350443 103.61339003 119.74939714 134.98601364  30.97966993\n",
            "  25.80147111  51.19010195  11.94618056 105.73284265  94.65099882\n",
            "  15.73758631  20.01532245  30.23792804  25.5454834   81.92407975\n",
            " 111.26085151  12.15559695  78.4515601   93.5888973    8.7675315\n",
            "  77.46246139  58.34007716  85.81263162 149.88514841 137.91280282\n",
            " 119.71173973  10.9816092   28.99966526  88.18208031  30.40346878\n",
            "  13.83048583  32.16261075  26.61344148  96.0801314  131.00527684\n",
            "  77.27946579  21.02885003  11.96629995  12.11447783  10.04982361\n",
            "  12.39975569  49.4118015   36.31051641  19.17155717  49.35442489\n",
            "  81.6388401   52.34686443  29.72094287  85.61041099  81.46885336\n",
            " 102.83268051  47.6261111   38.74832651  75.03546389  39.52803084\n",
            "  54.77666273  11.78686656  27.16569891 137.59239168  23.39068871\n",
            "  82.93538731  27.89505873  26.61978396  84.4701428   87.54054887\n",
            "  81.54364102 144.48402039  38.56910272  29.2317918   54.60207902\n",
            " 160.45080431  38.28636296  13.03122058  50.46364752  76.56311971\n",
            "  27.58164785  20.42848733  35.89301933  27.78993526 115.68184376\n",
            "  15.94124244  26.95818723  12.37873815  15.02039753 113.99476838\n",
            "  58.9696947  109.54409798  92.84704376  78.89905818  86.54432846\n",
            " 118.60612482  78.63380724  76.59029675  85.59649975  93.66337233\n",
            "  10.07742159  21.97040884  15.73355705  20.74163002  83.53082517\n",
            "  19.72563121  25.20906957  78.34058586  90.30463209  91.23883289\n",
            "  30.67354392  27.07643528 104.9675627   25.64388139  26.318808\n",
            "  28.24284271  93.02315938  78.34899362  19.80515027 104.28478445\n",
            "  85.98078355  19.92081437  18.11491773  97.33625881 105.85175618\n",
            "  93.43030231  55.2629365  102.06979785  51.77081895  53.02921844\n",
            " 110.56210515  84.76906411  15.65964336  77.38975265  13.69756421\n",
            "  14.46603437  82.79908481  43.21382705  23.83840925  26.1543228\n",
            " 104.67293302  39.35267029  86.38176277  20.44421083  29.12431605\n",
            "  22.28429859  29.66659635  74.89376343  29.08484875 107.07022992\n",
            "  27.28813861  82.28914981  53.95878829  32.77811597 100.62225717\n",
            " 105.54836098  55.50429949  50.17074223  54.67262775  89.11328976\n",
            "  31.80351147  27.66463548  23.33692724  97.96391251  10.30753791\n",
            "  13.20128615  94.02525241  39.75835862  34.07561102 139.80452706\n",
            "  45.01942756  83.20081432  12.83538693  76.10647467  77.20597319\n",
            "  12.68408915  54.28076331  92.51692793 136.47412833 144.22134809\n",
            "  20.80712362  10.19232427  26.41463184  84.10587463  11.36876986\n",
            " 126.97575894  19.87601954  48.13688664  94.20028035  51.84468384\n",
            "  42.92748955 106.76608017  40.47291774   9.88396483  14.78100161\n",
            " 146.35470289 115.36558936  12.50124708 111.54059556  81.52598206\n",
            "  27.82259882  84.85442562  12.86727033  86.95766852  19.82834435\n",
            " 114.81097799   9.9445474   33.65130128  90.26886236  10.56633374\n",
            "  78.07576147  33.2923874   11.97642047  80.67913676  39.77269159\n",
            "  14.89688923  83.0110695   47.00675855  84.10054342  86.29996321\n",
            "  18.82605796 101.967239    33.07691009 136.36394247  84.64098994\n",
            "  30.48675683  31.98925283 145.76521411  79.17790691  20.4021163\n",
            "  32.55575697 117.06094788  55.21175565  86.85023427  94.97863138\n",
            "  81.13676242 123.73990828  22.59012744 142.46469687  28.95836349]\n"
          ]
        }
      ],
      "execution_count": 17,
      "metadata": {
        "collapsed": false,
        "outputHidden": false,
        "inputHidden": false,
        "execution": {
          "iopub.status.busy": "2022-07-05T15:04:21.450Z",
          "iopub.execute_input": "2022-07-05T15:04:21.454Z",
          "iopub.status.idle": "2022-07-05T15:04:21.465Z",
          "shell.execute_reply": "2022-07-05T15:04:21.574Z"
        }
      }
    },
    {
      "cell_type": "code",
      "source": [
        "data = pd.DataFrame({'Actual': y_test.flatten(), 'Predicted' : predicted.flatten()})\n",
        "data.head(20)"
      ],
      "outputs": [
        {
          "output_type": "execute_result",
          "execution_count": 18,
          "data": {
            "text/plain": "        Actual   Predicted\n0    31.510000   31.421053\n1    27.420000   27.230902\n2   132.740005  134.789844\n3    13.000000   13.115749\n4    20.400000   20.654058\n5    44.150002   44.263588\n6    47.560001   47.472376\n7    90.620003   90.594553\n8    95.120003   94.994624\n9    19.430000   19.755712\n10   15.110000   14.213615\n11  113.459999  113.352560\n12   48.779999   48.663196\n13   80.110001   79.995924\n14   19.330000   19.055017\n15  107.650002  107.898749\n16   53.799999   54.130784\n17   55.900002   56.174877\n18   11.130000   11.636929\n19   85.070000   84.401971",
            "text/html": "<div>\n<style scoped>\n    .dataframe tbody tr th:only-of-type {\n        vertical-align: middle;\n    }\n\n    .dataframe tbody tr th {\n        vertical-align: top;\n    }\n\n    .dataframe thead th {\n        text-align: right;\n    }\n</style>\n<table border=\"1\" class=\"dataframe\">\n  <thead>\n    <tr style=\"text-align: right;\">\n      <th></th>\n      <th>Actual</th>\n      <th>Predicted</th>\n    </tr>\n  </thead>\n  <tbody>\n    <tr>\n      <th>0</th>\n      <td>31.510000</td>\n      <td>31.421053</td>\n    </tr>\n    <tr>\n      <th>1</th>\n      <td>27.420000</td>\n      <td>27.230902</td>\n    </tr>\n    <tr>\n      <th>2</th>\n      <td>132.740005</td>\n      <td>134.789844</td>\n    </tr>\n    <tr>\n      <th>3</th>\n      <td>13.000000</td>\n      <td>13.115749</td>\n    </tr>\n    <tr>\n      <th>4</th>\n      <td>20.400000</td>\n      <td>20.654058</td>\n    </tr>\n    <tr>\n      <th>5</th>\n      <td>44.150002</td>\n      <td>44.263588</td>\n    </tr>\n    <tr>\n      <th>6</th>\n      <td>47.560001</td>\n      <td>47.472376</td>\n    </tr>\n    <tr>\n      <th>7</th>\n      <td>90.620003</td>\n      <td>90.594553</td>\n    </tr>\n    <tr>\n      <th>8</th>\n      <td>95.120003</td>\n      <td>94.994624</td>\n    </tr>\n    <tr>\n      <th>9</th>\n      <td>19.430000</td>\n      <td>19.755712</td>\n    </tr>\n    <tr>\n      <th>10</th>\n      <td>15.110000</td>\n      <td>14.213615</td>\n    </tr>\n    <tr>\n      <th>11</th>\n      <td>113.459999</td>\n      <td>113.352560</td>\n    </tr>\n    <tr>\n      <th>12</th>\n      <td>48.779999</td>\n      <td>48.663196</td>\n    </tr>\n    <tr>\n      <th>13</th>\n      <td>80.110001</td>\n      <td>79.995924</td>\n    </tr>\n    <tr>\n      <th>14</th>\n      <td>19.330000</td>\n      <td>19.055017</td>\n    </tr>\n    <tr>\n      <th>15</th>\n      <td>107.650002</td>\n      <td>107.898749</td>\n    </tr>\n    <tr>\n      <th>16</th>\n      <td>53.799999</td>\n      <td>54.130784</td>\n    </tr>\n    <tr>\n      <th>17</th>\n      <td>55.900002</td>\n      <td>56.174877</td>\n    </tr>\n    <tr>\n      <th>18</th>\n      <td>11.130000</td>\n      <td>11.636929</td>\n    </tr>\n    <tr>\n      <th>19</th>\n      <td>85.070000</td>\n      <td>84.401971</td>\n    </tr>\n  </tbody>\n</table>\n</div>"
          },
          "metadata": {}
        }
      ],
      "execution_count": 18,
      "metadata": {
        "collapsed": false,
        "outputHidden": false,
        "inputHidden": false,
        "execution": {
          "iopub.status.busy": "2022-07-05T15:04:21.471Z",
          "iopub.execute_input": "2022-07-05T15:04:21.475Z",
          "iopub.status.idle": "2022-07-05T15:04:21.484Z",
          "shell.execute_reply": "2022-07-05T15:04:21.579Z"
        }
      }
    },
    {
      "cell_type": "code",
      "source": [
        "print('Mean Absolute Error:', metrics.mean_absolute_error(y_test,predicted))\n",
        "print('Mean Squared Error:', metrics.mean_squared_error(y_test,predicted))\n",
        "print('Root Mean Squared Error:', math.sqrt(metrics.mean_squared_error(y_test,predicted)))"
      ],
      "outputs": [
        {
          "output_type": "stream",
          "name": "stdout",
          "text": [
            "Mean Absolute Error: 0.5090041265549652\n",
            "Mean Squared Error: 0.5595658563710334\n",
            "Root Mean Squared Error: 0.7480413466988529\n"
          ]
        }
      ],
      "execution_count": 19,
      "metadata": {
        "collapsed": false,
        "outputHidden": false,
        "inputHidden": false,
        "execution": {
          "iopub.status.busy": "2022-07-05T15:04:21.491Z",
          "iopub.execute_input": "2022-07-05T15:04:21.496Z",
          "shell.execute_reply": "2022-07-05T15:04:21.581Z",
          "iopub.status.idle": "2022-07-05T15:04:21.506Z"
        }
      }
    },
    {
      "cell_type": "code",
      "source": [
        "bar_chart = data.head(20)\n",
        "bar_chart.plot(kind='bar')"
      ],
      "outputs": [
        {
          "output_type": "execute_result",
          "execution_count": 20,
          "data": {
            "text/plain": "<AxesSubplot:>"
          },
          "metadata": {}
        },
        {
          "output_type": "display_data",
          "data": {
            "text/plain": "<Figure size 432x288 with 1 Axes>",
            "image/png": "iVBORw0KGgoAAAANSUhEUgAAAXcAAAD9CAYAAABHnDf0AAAAOXRFWHRTb2Z0d2FyZQBNYXRwbG90bGliIHZlcnNpb24zLjMuNCwgaHR0cHM6Ly9tYXRwbG90bGliLm9yZy8QVMy6AAAACXBIWXMAAAsTAAALEwEAmpwYAAAaQUlEQVR4nO3de3hU9b3v8fe3gCJiEUI2RSI7OS3aRg4gBkRFiuKBtCjeK2oVLJT6bG9baqvu7qfgfk57qPt4KeyjmC2tuKtRS7FoFesNmloPKjcBiRcqAWIRIijWWyX43X+sRToMCVlzCRl+fl7PM0/W+q31+853JplvfvObtdaYuyMiImH5QnsnICIi+afiLiISIBV3EZEAqbiLiARIxV1EJEAq7iIiAWq1uJvZL8xsq5mtaWbb983MzaxnvG5mNtPM1pnZKjMb3BZJi4jIviUZud8DVKY3mtmRwGhgY0rzN4B+8W0KcGfuKYqISKY6traDu9eYWWkzm24DfggsSGk7E7jXozOjlpjZ4WbW29037+s+evbs6aWlzd2FiIi0ZNmyZe+4e3Fz21ot7s0xszOBt9z9ZTNL3dQH2JSyXh+37bO4l5aWsnTp0mxSERH53DKzDS1ty7i4m1kX4F+IpmRySWoK0dQNffv2zSWUiIikyeZomS8DZcDLZlYHlADLzexLwFvAkSn7lsRte3H3KnevcPeK4uJm31WIiEiWMi7u7r7a3f/B3UvdvZRo6mWwu78NPAJcGh81MwzY0dp8u4iI5F+r0zJmVg2MBHqaWT0wzd3ntLD748A3gXXAR8BlecpTRA5AO3fupL6+nk8++aS9Uzmgde7cmZKSEjp16pS4T5KjZS5sZXtpyrIDVyS+dxEJWn19PYcddhilpaWkHXwhCbk727Zto76+nrKyssT9dIaqiLSZTz75hKKiIhX2HJgZRUVFGb/7UXEXkTalwp67bJ5DFXcRCd5vf/tbzIxXX311n/vdfvvtfPTRR1nfzz333MOVV16Zdf98yuokps+t6d3S1ne0Tx4iB6jSGx7La7y6GWMT7VddXc3w4cOprq7mpptuanG/22+/nW9/+9t06dIlXym2G43cRSRoH3zwAc899xxz5szhgQceAGDXrl1cd9119O/fnwEDBjBr1ixmzpzJX/7yF0455RROOeUUALp27doUZ968eUycOBGARx99lOOPP55jjz2W0047jS1btuz3x9UajdxFJGgLFiygsrKSo446iqKiIpYtW8aLL75IXV0dK1eupGPHjmzfvp0ePXpw6623smjRInr27LnPmMOHD2fJkiWYGXfffTc333wzt9xyy356RMmouO9D+lvIus7tlIiIZK26upprrrkGgPHjx1NdXc369eu5/PLL6dgxKoE9evTIKGZ9fT0XXHABmzdv5tNPP83oEMX9RcVdRIK1fft2nn32WVavXo2ZsWvXLsyMIUOGJOqfepRK6qGIV111FVOnTmXcuHEsXryY6dOn5zv1nGnOXUSCNW/ePC655BI2bNhAXV0dmzZtoqysjIEDB3LXXXfR2NgIRP8EAA477DD++te/NvXv1asXtbW1fPbZZzz88MNN7Tt27KBPnz4AzJ07dz8+ouRU3EUkWNXV1Zx99tl7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wb+g4TvPFL61sV/MOvjn71TRgkrE8boRlQM/hw/pp1xrD8QTcskibFiH9u6JOh/bXyfG4CrgWeA/yQabU5LmMM1RKPC/yQaeV8WtxcDNQljvJbNtrT9dsV/X4uauX2cMMbKtPUfAX8iGj23+rfFnu/oNu4r9j5ifD9+bf7PlLb1Gf59Lm/pfjPIoxboGC8vSdvW6rvTtBxOJirGb8e/jykJc9jX87kiYYyX09Zfin9+gehzusTPq7sXXnFPeTDDgHPj2zDit9MJ+88Bhrew7f6EMUqAL7Ww7aSEMQ5uob1n6gsig8c1lugDzHw8x12Asgz7fBEYCBxHwrfMKX2PykPORwBHxMuHA+cBQzOMcUzc76tZ5vAk8MPUx0/0bvB64OmEMdYA/VrYtilhjFpSBgxx20Sit/QbEvR/OWX5f6dtSzRdF++7e+BxK9G7qjczfD7rganxP4o3iT8HjLclnW67Kv69nEo0vfRzoqnLm4D/StB/r3+GRNOplcAvE+bw/4mmHM8nGoCcFbd/nYQX/yIa8Q+Pl8ex58UXEw0c9oiXaQfddPs834jewv+Mv8+5b48L7c+A7gljnAcc3cK2sxLGuBk4rZn2ShJ8NkU0t9u1mfavAPOyeF7GEc0Pv51hv2lpt92fCX0JuDeDOCOBB4k+21lNdOmTKcQj+lb6PpCHv4uBRNfSWgh8Nf4H8178z/bEhDEGAC8STfE9RzwgInpneXWmORXc0TIiB6qkR2IVeoxs+8eHyX7Z3dcUwuPIR4xCyCHbGCruInliZhvdve+BHqMQciiUGIWQQ7YxCvIkJpFCZWarWtpEwiOxCiFGIeRQKDEKIYd8xUil4i6SmV5Eh6q9m9ZuRB+IHSgxCiGHQolRCDnkK0YTFXeRzPyO6IPIlekbzGzxARSjEHIolBiFkEO+Yvy9j+bcRUTCU4hnqIqISI5U3EVEAqTiLiISIBV3EZEAqbiLiATovwFqjGQcCsd+zgAAAABJRU5ErkJggg==\n"
          },
          "metadata": {
            "needs_background": "light"
          }
        }
      ],
      "execution_count": 20,
      "metadata": {
        "collapsed": false,
        "outputHidden": false,
        "inputHidden": false,
        "execution": {
          "iopub.status.busy": "2022-07-05T15:04:21.512Z",
          "iopub.execute_input": "2022-07-05T15:04:21.519Z",
          "iopub.status.idle": "2022-07-05T15:04:21.630Z",
          "shell.execute_reply": "2022-07-05T15:04:21.624Z"
        }
      }
    }
  ],
  "metadata": {
    "kernel_info": {
      "name": "python3"
    },
    "language_info": {
      "name": "python",
      "version": "3.6.13",
      "mimetype": "text/x-python",
      "codemirror_mode": {
        "name": "ipython",
        "version": 3
      },
      "pygments_lexer": "ipython3",
      "nbconvert_exporter": "python",
      "file_extension": ".py"
    },
    "kernelspec": {
      "name": "python3",
      "language": "python",
      "display_name": "Python 3"
    },
    "nteract": {
      "version": "0.28.0"
    }
  },
  "nbformat": 4,
  "nbformat_minor": 0
}